package kislo.dima.task4;

public class PlusMinus {

	public static Matrix add(Matrix a, Matrix b) throws PlusMinusException {
		int mSizeA = a.getRowCount();
		int nSizeA = a.getColumnCount();
		int mSizeB = b.getRowCount();
		int nSizeB = b.getColumnCount();

		if ((mSizeA != mSizeB) || (nSizeA != nSizeB))
			throw new PlusMinusException();

		Matrix c = new Matrix(mSizeA, nSizeA);

		for (int i = 0; i < mSizeA; i++) {
			for (int j = 0; j < mSizeB; j++) {
				c.setElement(i, j, a.getElement(i, j) + b.getElement(i, j));
			}
		}

		return c;
	}
	
	public static Matrix subtract(Matrix a, Matrix b) throws PlusMinusException {
		int mSizeA = a.getRowCount();
		int nSizeA = a.getColumnCount();
		int mSizeB = b.getRowCount();
		int nSizeB = b.getColumnCount();

		if ((mSizeA != mSizeB) || (nSizeA != nSizeB))
			throw new PlusMinusException();

		Matrix c = new Matrix(mSizeA, nSizeA);

		for (int i = 0; i < mSizeA; i++) {
			for (int j = 0; j < mSizeB; j++) {
				c.setElement(i, j, a.getElement(i, j) - b.getElement(i, j));
			}
		}

		return c;
	}
}
